package com.example.demo.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mall.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    // 根据用户名查询用户
    @Select("SELECT * FROM user1 WHERE username = #{username}")
    User selectByUsername(@Param("username") String username);

    // 根据邮箱查询用户
    @Select("SELECT * FROM user1 WHERE email = #{email}")
    User selectByEmail(@Param("email") String email);

    // 根据手机号查询用户
    @Select("SELECT * FROM user1 WHERE phone = #{phone}")
    User selectByPhone(@Param("phone") String phone);

    // 根据角色查询用户列表
    @Select("SELECT * FROM user1 WHERE role = #{role}")
    List<User> selectByRole(@Param("role") String role);

    // 更新用户状态
    @Update("UPDATE user1 SET status = #{status} WHERE id = #{id}")
    int updateStatusById(@Param("id") Long id, @Param("status") Integer status);

    // 更新用户密码
    @Update("UPDATE user1 SET password = #{newPassword} WHERE id = #{id}")
    int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword);


}
